package test.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.junit.Test;

import test.service.BaseTest;
import blog.core.exception.FormParamErrorException;
import blog.core.exception.NotFoundException;
import blog.spring.db.entity.ArticleContent;
import blog.spring.db.entity.ArticleInfo;
import blog.spring.db.service.IArticleService;

public class ArticleService extends BaseTest<ArticleInfo> {

	@Resource
	private IArticleService articleService;

	@Override
	public void init() {
		entity = new ArticleInfo();
		entity.setTitle("我是置顶文章");
		entity.setIsTop(true);
		ArticleContent content = new ArticleContent();
		content.setContent("我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。我是文章内容。。。");
		entity.setArticleContent(content);
//		entity.setType(new Type(112));
	}

	@Override
	public void a_save() throws FormParamErrorException {
		articleService.save(entity);
	}

	@Override
	public void b_findByName() {
		// TODO Auto-generated method stub

	}

	@Override
	public void c_findById() {
		articleService.findById(1);
	}

	@Override
	public void d_update() throws FormParamErrorException {
		// TODO Auto-generated method stub

	}

	@Override
	public void e_remove() {
		// TODO Auto-generated method stub

	}

	@Override
	public void f_addMulti() throws FormParamErrorException {
		// TODO Auto-generated method stub

	}

	@Override
	public void g_findList() {
		List<ArticleInfo> as = articleService.findList(1, 10, "createDate",
				"desc");
		for (ArticleInfo a : as) {
			System.out.println(a.getCreateDate());
		}

	}

	@Override
	public void h_searchList() {
		Map<String, Object> conditions = new HashMap<String, Object>();
		conditions.put("title", "测试");
		List<ArticleInfo> as = articleService.searchList(conditions, 1, 10,
				"createDate", "desc", true);
		for (ArticleInfo a : as) {
			System.out.println(a.getCreateDate());
		}
	}

	@Override
	public void i_searchUnique() {
		// TODO Auto-generated method stub

	}

	@Test
	public void j_addTo() throws FormParamErrorException, NotFoundException {
		articleService.addTo(5, "12434213423423423");
	}

	@Test
	public void k_indexList() {
		List<ArticleInfo> as = articleService.indexList(1);
		for (ArticleInfo a : as) {
			System.out.println(a.getTitle() + ":" + a.getCreateDate());
		}
	}

	@Test
	public void l_findHot(){
		List<ArticleInfo> as = articleService.findHot(3);
		for (ArticleInfo info : as) {
			System.out.println(info.getCommentCount());
		}
	}
}
